package main

import (
	"fmt"
	"net/http"

	"gitee.com/lvshicong/script_exporter.git/controller"
)

func main() {
	// // 可选: 添加 process 和 Go 运行时指标到我们自定义的注册表中
	// registry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
	// registry.MustRegister(prometheus.NewGoCollector())
	http.HandleFunc("/metrics", ScriptHandler)
	http.ListenAndServe(":8050", nil)
}

func ScriptHandler(w http.ResponseWriter, r *http.Request) {
	sc := controller.NewScriptCollector("module")
	qs := r.URL.Query()
	// ?module=amq.exe&params=localhost
	err := sc.Exec(qs.Get("module"), qs.Get("params"), w)
	if err != nil {
		fmt.Fprintf(w, "exec error: %s", err)
	}
}
